package com.example.demo;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration

public class SecurityConfig {
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        // 禁用 CSRF 防护（适用于 RESTful API）
        http.csrf(csrf -> csrf.disable())
                // 配置请求权限
                .authorizeHttpRequests(authorizeRequests ->
                        authorizeRequests
                                // 放行登录和注册接口
                                .requestMatchers("/*").permitAll()
                                // 其他请求需要认证
                                .anyRequest().authenticated()
                )
                // 禁用表单登录，采用其他认证方式
                .formLogin(form -> form.disable());

        return http.build();
    }
}